package com.shakespace.artofandroid.chapter03.conflict

import android.graphics.Color
import android.os.Bundle
import android.view.View
import android.widget.ArrayAdapter
import android.widget.ListView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.shakespace.artofandroid.R
import com.shakespace.firstlinecode.global.screenWidth
import kotlinx.android.synthetic.main.activity_confilct.*

class ConflictActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_confilct)


        for (i in 0..2) {
            val view = layoutInflater.inflate(R.layout.confilct_test_layout, horizontal_view, false)
            view.layoutParams.width = screenWidth

            val tv_title: TextView = view.findViewById(R.id.title)
            tv_title.text = "Page $i"
            view.setBackgroundColor(Color.rgb(255 / (i + 1), 255 / (i * i + 1), 255 / (i * i * i * i + 1)))
            createList(view)
            horizontal_view.addView(view)
        }
    }

    private fun createList(view: View) {
        val listView = view.findViewById<ListView>(R.id.list_view)
        val datalist = arrayListOf<String>().let {
            for (i in 0..50) {
                it.add("item $i")
            }
            it
        }

        val adapter = ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, datalist)
        listView.adapter = adapter
    }
}
